package cn.mw.cmdb.controller;

import cn.mw.cmdb.entity.instanceToPo.InstanceViewInfo;
import cn.mw.cmdb.entity.instanceToPo.QueryInstanceRelationToPoParam;
import cn.mw.cmdb.entity.modelRelation.ModelAlertWeightInfo;
import cn.mw.cmdb.param.TrendQueryParam;
import cn.mw.cmdb.service.InstanceToPoService;
import cn.mw.microMonitorCommon.api.common.BaseApiService;
import cn.mw.microMonitorCommon.api.common.ResponseBase;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/instanceToPo")
@Controller
@Tag(name = "实例拓扑")
@Slf4j
public class InstanceToPoController extends BaseApiService {

    @Autowired
    private InstanceToPoService instanceToPoService;

    @PostMapping("/createInstanceView")
    @ResponseBody
    @ApiOperation(value = "创建实例视图")
    public ResponseBase createInstanceView(@RequestBody InstanceViewInfo param) {
        return setResultSuccess(instanceToPoService.createInstanceView(param));
    }

    @PostMapping("/editInstanceView")
    @ResponseBody
    @ApiOperation(value = "编辑实例视图")
    public ResponseBase editInstanceView(@RequestBody InstanceViewInfo param) {
        return setResultSuccess(instanceToPoService.editInstanceView(param));
    }

    @PostMapping("/deleteInstanceView")
    @ResponseBody
    @ApiOperation(value = "删除实例视图")
    public ResponseBase deleteInstanceView(@RequestBody InstanceViewInfo param) throws Exception {
        return setResultSuccess(instanceToPoService.deleteInstanceView(param));
    }

    @PostMapping("/getInstanceView")
    @ResponseBody
    @ApiOperation(value = "查询实例视图")
    public ResponseBase getInstanceView(@RequestBody InstanceViewInfo param) throws Exception {
        return setResultSuccess(instanceToPoService.getInstanceView(param));
    }

    @PostMapping("/dealInstanceToPo")
    @ResponseBody
    @ApiOperation(value = "处理实例拓扑数据")
    public ResponseBase dealInstanceToPo(@RequestBody QueryInstanceRelationToPoParam param) throws Exception {
        return setResultSuccess(instanceToPoService.dealInstanceToPo(param));
    }

    @PostMapping("/getModelRelationInfo")
    @ResponseBody
    @ApiOperation(value = "获取关联模型下拉选择")
    public ResponseBase getModelRelationInfo(@RequestBody QueryInstanceRelationToPoParam param) throws Exception {
        return setResultSuccess(instanceToPoService.getModelRelationInfo(param));
    }

    @PostMapping("/saveInstanceToPo")
    @ResponseBody
    @ApiOperation(value = "保存实例拓扑数据")
    public ResponseBase saveInstanceToPo(@RequestBody QueryInstanceRelationToPoParam param) throws Exception {
        return setResultSuccess(instanceToPoService.addInstanceToPo(param));
    }

    @PostMapping("/getInstanceTopoSelTree")
    @ResponseBody
    @ApiOperation(value = "查询能够选择的实例关系")
    public ResponseBase getInstanceTopoSelTree(@RequestBody QueryInstanceRelationToPoParam param) throws Exception {
        return setResultSuccess(instanceToPoService.getInstanceTopoSelTree(param));
    }

    @PostMapping("/addOrUpdateModelAlertWeightInfo")
    @ResponseBody
    @ApiOperation(value = "新增或修改模型权重配置")
    public ResponseBase addOrUpdateModelAlertWeightInfo(@RequestBody ModelAlertWeightInfo param) throws Exception {
        return setResultSuccess(instanceToPoService.addOrUpdateModelAlertWeightInfo(param));
    }

    @PostMapping("/deleteModelAlertWeightInfo")
    @ResponseBody
    @ApiOperation(value = "删除模型权重")
    public ResponseBase deleteModelAlertWeightInfo(@RequestBody ModelAlertWeightInfo param) throws Exception {
        return setResultSuccess(instanceToPoService.deleteModelAlertWeightInfo(param));
    }

    @PostMapping("/getModelAlertWeightInfo")
    @ResponseBody
    @ApiOperation(value = "查看模型权重")
    public ResponseBase getModelAlertWeightInfo(@RequestBody ModelAlertWeightInfo param) throws Exception {
        return setResultSuccess(instanceToPoService.getModelAlertWeightInfo(param));
    }

    @GetMapping("/getAlertWeightConfigInfosByInstanceId")
    @ResponseBody
    @ApiOperation(value = "根据实例ID查询关联业务实例")
    public ResponseBase deleteModelAlertWeightInfo(String instanceId) throws Exception {
        return setResultSuccess(instanceToPoService.getAlertWeightConfigInfosByInstanceId(instanceId));
    }

    @GetMapping("/getRelationInstanceIds")
    @ResponseBody
    @ApiOperation(value = "查询关联实例ID列表")
    public ResponseBase getRelationInstanceIds(String modelId, String instanceId) throws Exception {
        return setResultSuccess(instanceToPoService.getRelationInstanceIds(modelId, instanceId));
    }

    @PostMapping("/getBusinessHealthTrend")
    @ResponseBody
    @ApiOperation(value = "获取业务健康度趋势")
    public ResponseBase getRelationInstanceIds(String instanceId, @RequestBody TrendQueryParam queryParam) throws Exception {
        return setResultSuccess(instanceToPoService.getBusinessHealthTrend(instanceId, queryParam));
    }
}
